// JavaScript Document
/**
 * Created by wangfan on 2017/5/21.
 */

function getUrl(url, params) {
    for (var i = 0; i < params.length; i++) {
        if ($("#" + params[i]).val() != "") {
            url = url + "&" + params[i] + "=" + $("#" + params[i]).val();
        }
    }
    return url;

}
function getUrlParam(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r!=null) return unescape(r[2]); return null; //返回参数值
}
function countNotify(result,type) {
    var count =
        parseInt(result.data.allBackNotify)+
        parseInt(result.data.addProNotify)+
        parseInt(result.data.attNotify)+
        parseInt(result.data.overtimeNotify)+
        parseInt(result.data.delProNotify)+
        parseInt(result.data.fundNotify)+
        parseInt(result.data.fundCommunityNotify)+
        parseInt(result.data.officeCommunityNotify)+
        parseInt(result.data.publicFundCommunityNotify)+
        parseInt(result.data.constructionCommunityNotify)+
        parseInt(result.data.publicFundOrgNotify)+
        parseInt(result.data.constructionOrgNotify)+
        parseInt(result.data.officeNotify)+
        parseInt(result.data.publicFundNotify)+
        parseInt(result.data.constructionNotify)
    ;

    if(type){
        if(0===count){

            $('#xxsl').hide();
        }else{
            $('#xxsl').show();
            $('#xxsl').html(count);
        }

    }else{
        if (0 === count) {
            window.parent.$('#xxsl').hide();
        } else {
            window.parent.$('#xxsl').show();
            window.parent.$('#xxsl').html(count);
        }

    }

    return count;


}

function formatStringyyyyMMddTochinese (value){
    if(value.length >=10){
        return value.substring(0, 4) + "年" + value.substring(5, 7) + "月" + value.substring(8, 10)+ "日";
    } else if(value.length == 7){
        return value.substring(0, 4) + "年" + value.substring(5, 7);
    } else {
        return value;
    }
}
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
    return currentdate;
}

function getNowFormatDateShort() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + "" ;
    return currentdate;
}

var localStorageFunc = {
    //获取 localStorage
    getStorage:function(storage){
        var str = localStorage.getItem(storage);
        if(str != null && str != ''){
            var obj = JSON.parse(JSON.parse(str));
            return obj;
        }
    },
    //设置 localStorage 未嵌套
    setStorage:function(storage,key,val){
        var obj = this.getStorage(storage);
        var saveObj = this.utilStorage(obj,key,val);
        localStorage.setItem(storage,saveObj);
    },
    //设置 localStorage 嵌套
    secondStorage:function(storage,tagKey,key,val){
        var obj = this.levelStorage(storage,tagKey,key,val);
        this.setStorage(storage,tagKey,obj);
    },
    //清除 localStorage
    clearStorage:function(storage){
        localStorage.removeItem(storage);
    },
    //json 整理格式化
    utilStorage:function(obj,key,val){
        if(typeof obj == 'object'){
            obj[key] = val;
            var str = JSON.stringify(obj);
            str = str.replace(/\\/g,'');
            obj = JSON.stringify(str);
        }else{
            var item = '{"'+key+'":"' + val + '"}';
            obj = JSON.stringify(item);
        }
        return obj;
    },
    //次级json  整理格式化
    levelStorage:function(storage,tagObj,key,val){
        var tag = this.getStorage(storage);
        var tagItem = tag[tagObj];
        if(typeof tagItem == 'object'){
            tagItem[key] = val;
        }else if(tagItem == undefined){
            tagItem = '{"'+key+'":"' + val + '"}';
            tagItem = JSON.parse(tagItem);
        }
        return tagItem;
    }
};
